/*
 * @Author: dvlproad
 * @Date: 2023-10-30 18:40:55
 * @LastEditors: dvlproad
 * @LastEditTime: 2023-10-31 19:47:16
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

import 'ts_shared_webview_notifier.dart';

class TSSharedWebViewContainer extends StatelessWidget {
  // late WebViewWidget _webViewWidget;
  // late WebViewController _webController;

  const TSSharedWebViewContainer({super.key});

  // @override
  // void initState() {
  //   super.initState();

  //   _webController = defaultController;
  //   _webViewWidget = WebViewWidget(controller: _webController);
  //   // widget.onWebViewCreated?.call(_webViewWidget, _webController);

  //   _addJs();

  //   _loadRequest();
  // }

  @override
  Widget build(BuildContext context) {
    // return MultiProvider(
    //   providers: [
    //     ChangeNotifierProvider(
    //         create: (_) => TSSharedWebViewContainerModel()),
    //   ],
    //   child: _buildContent(context),
    // );
    return _buildContent(context);
  }

  Widget _buildContent(BuildContext context) {
    /// Calls `context.read` instead of `context.watch` so that it does not rebuild when [Counter] changes.
    var model_read = context.read<TSSharedWebViewContainerModel>();

    /// Calls `context.watch` to make [Count] rebuild when [Counter] changes.
    var model_watch = context.watch<TSSharedWebViewContainerModel>();

    return Container(
      color: Colors.green,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Text(
            '我是一个视图实例',
            style: TextStyle(fontSize: 16),
          ),
          ElevatedButton(
            onPressed: model_watch.addCount,
            style: ElevatedButton.styleFrom(
              backgroundColor: Colors.grey,
              foregroundColor: Colors.red,
            ),
            child: const Text('点击我'),
          ),
          Text(
            '${model_watch.count}',
            style: const TextStyle(fontSize: 16),
          ),
          Container(
            color: Colors.cyan,
            width: 370,
            height: 300,
            child: WebViewWidget(controller: model_read.webController),
          ),
        ],
      ),
    );
  }
}
